package com.javastudy.autowiredStudy.defineBean;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author mac
 * @date 2021/9/10 4:40 下午
 */
public class CustomImportSelector implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        RootBeanDefinition roleBeanDefinition = new RootBeanDefinition(Person.class);
        registry.registerBeanDefinition("person", roleBeanDefinition);

        RootBeanDefinition userBeanDefinition = new RootBeanDefinition(Person.class);
        //设置bean的类型 
        userBeanDefinition.setScope(ConfigurableBeanFactory.SCOPE_PROTOTYPE);
        registry.registerBeanDefinition("person", userBeanDefinition);
    }
}
